﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class QuitStatistic : System.Web.UI.Page
{
    public string totalnum = "";
    public string totalmon = "";
    public string Sqlstr = "";
    public string flag = "0";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            ddlStroe.Items.Add(new ListItem("-全部-"));
            ddlQuit.Items.Add(new ListItem("-全部-"));
            ddlDepartment.Items.Add(new ListItem("-全部-"));
            ddlCustomer.Items.Add(new ListItem("-全部-"));
            this.Bind();
        }
    }
    public void Bind()
    {
        DataSet ds1 = DB.reDs("select Title from tb_BigType where Type='仓库'");
        ddlStroe.DataSource = ds1;
        ddlStroe.DataTextField = "Title";
        ddlStroe.DataBind();
        DataSet ds2 = DB.reDs("select Title from tb_BigType where Type='出库类型'");
        ddlQuit.DataSource = ds2;
        ddlQuit.DataTextField = "Title";
        ddlQuit.DataBind();
        DataSet ds3 = DB.reDs("select Title from tb_BigType where type='部门'");
        ddlDepartment.DataSource = ds3;
        ddlDepartment.DataTextField = "Title";
        ddlDepartment.DataBind();
        DataSet ds4 = DB.reDs("select Name from tb_Enterprise where type3='是'");
        ddlCustomer.DataSource = ds4;
        ddlCustomer.DataTextField = "Name";
        ddlCustomer.DataBind();
    }
  
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (this.ddlStroe.SelectedValue != "-全部-")
        {
            if (flag == "0")
            {
                Sqlstr = Sqlstr + " where " + "B.StorePlace='" + this.ddlStroe.SelectedValue.ToString() + "'";
            }
            else
            {
                Sqlstr = Sqlstr + "  and  " + "B.StorePlace='" + this.ddlStroe.SelectedValue.ToString() + "'";
            }
            flag = "1";
        }
        if (this.ddlQuit.SelectedValue != "-全部-")
        {
            if (flag == "0")
            {
                Sqlstr = Sqlstr + "  where  " + "B.QuitType='" + this.ddlQuit.SelectedValue.ToString() + "'";
            }
            else
            {
                Sqlstr = Sqlstr + "  and " + "B.QuitType='" + this.ddlQuit.SelectedValue.ToString() + "'";
            }
            flag = "1";
        }
        if (this.ddlDepartment.SelectedValue != "-全部-")
        {
            if (flag == "0")
            {
                Sqlstr = Sqlstr + " where  " + "B.QuitDepartment='" + this.ddlDepartment.SelectedValue.ToString() + "'";
            }
            else
            {
                Sqlstr = Sqlstr + " and " + "B.QuitDepartment='" + this.ddlDepartment.SelectedValue.ToString() + "'";
            }
            flag = "1";
        }
        if (this.txtQuitMan.Text != "")
        {
            if (flag == "0")
            {
                Sqlstr = Sqlstr + " where " + "B.QuitMan='" + this.txtQuitMan.Text.Trim() + "'";
            }
            else
            {
                Sqlstr = Sqlstr + " and " + "B.QuitMan='" + this.txtQuitMan.Text.Trim() + "'";
            }
            flag = "1";
        }
        if (this.txtSign.Text != "")
        {
            if (flag == "0")
            {
                Sqlstr = Sqlstr + " where " + "B.OutMan='" + this.txtSign.Text.ToString() + "'";
            }
            else
            {
                Sqlstr = Sqlstr + " and " + "B.OutMan='" + this.txtSign.Text.ToString() + "'";
            }
            flag = "1";
        }
        if (this.ddlCustomer.SelectedValue != "-全部-")
        {

            if (flag == "0")
            {
                Sqlstr = Sqlstr + " where " + "B.Name='" + this.ddlCustomer.SelectedValue.ToString() + "'";
            }
            else
            {
                Sqlstr = Sqlstr + " and " + "B.Name='" + this.ddlCustomer.SelectedValue.ToString() + "'";
            }
            flag = "1";
        }
        DataSet ds1 = DB.reDs("select sum(A.Amount) as amount , sum(A.Gathering) as gathering from tb_QuitDetails as A inner join tb_Quit as B on A.QuitID=B.QuitID" + Sqlstr);
        totalnum = ds1.Tables[0].Rows[0][0].ToString();
        totalmon = ds1.Tables[0].Rows[0][1].ToString();
        DataSet ds = DB.reDs("select DISTINCT A.WzID, A.Name,A.Modle,A.Spec,A.Card from tb_QuitDetails as A inner join tb_Quit as B on A.QuitID=B.QuitID" + Sqlstr);
        this.DataList1.DataSource = ds;
        this.DataList1.DataBind();
    }
}
